#!/bin/bash -x

if [ ! -f crystax-ndk-10.3.2 ]; then
 df -h .

 if [ `uname -m` = x86_64 ]; then
	NDK_URL=https://www.crystax.net/download/crystax-ndk-10.3.2-linux-x86_64.tar.xz;
 else
	NDK_URL=https://www.crystax.net/download/crystax-ndk-10.3.2-linux-x86.tar.xz;
 fi

 trap "rm -f tarpipe" EXIT

 mkfifo tarpipe

 set +x

 wget -v --no-check-certificate --progress=dot:giga -O tarpipe "$NDK_URL" 2>&1 | while IFS='' read -r line; do printf "\n%s" "$line"; done &

 tar --get --xz --checkpoint=3000 --file=tarpipe crystax-ndk-10.3.2 \
	--exclude=crystax-ndk-10.3.2/docs \
	--exclude=crystax-ndk-10.3.2/samples \
	--exclude=crystax-ndk-10.3.2/tests \
	--exclude=crystax-ndk-10.3.2/toolchains/renderscript \
	--exclude=crystax-ndk-10.3.2/toolchains/x86_64-* \
	--exclude=crystax-ndk-10.3.2/toolchains/llvm-* \
	--exclude=crystax-ndk-10.3.2/toolchains/aarch64-* \
	--exclude=crystax-ndk-10.3.2/toolchains/mips64el-* 2>&1 | while IFS='' read -r line; do printf "\t\n%s" "$line"; done

 printf "\n"

 set -x

 ls crystax-ndk-10.3.2 | wc -l
fi

echo ndk.dir=`pwd`/crystax-ndk-10.3.2 > local.properties
